import { MenuDataItem,MenuItem } from "@/types/Menu";
import * as icons from '@ant-design/icons'
import React from "react";
import {RouteObject} from 'react-router-dom'

export const transformMenuDataToAntdMenu=(sourceAry:Array<MenuDataItem>):Array<MenuItem>=>{
    return sourceAry.map(item=>{
        const antMenuItem:MenuItem={
            key:item.path,
            label:item.name
        }
        if(item.children){
            antMenuItem.children=transformMenuDataToAntdMenu(item.children)
        }
        if(item.icon){
           let v=item.icon.replace(/-o$/,"").replace(/^[a-z]/,(letter:string)=>letter.toUpperCase()).replace(/-[a-z]/,(letter:string)=>letter[1].toUpperCase())+"Outlined"
           let icon:any=icons[v as keyof typeof icons]    
           if(icon){
            antMenuItem.icon=React.createElement(icon)
           }
          
        }
        return antMenuItem
    }).filter(item=>item.key!='/profile')
}

export const getAllChild=(source:Array<MenuDataItem>,dist:Array<string>)=>{
    source.forEach(item=>{
        if(item.children){
            getAllChild(item.children,dist)
        }else{
            dist.push(item.path)
        }
    })
}

// export function getDynamicRouteChildren(routes:Array<MenuDataItem>,childList:Array<any>){
//     //找到home所在路由
//     for(let i=0;i<routes.length;i++){
//         let route=routes[i]
//         if(route.path==="/home"){
//             let filterAry=route.children?.filter(item=>{
//                if(childList.map(item=>item.url).includes(item.path)){
//                  return true
//                }
//             })
//             return filterAry
//         }
//     }
// }
